<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>登录</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="css/login.css"/>
    <script src="../js/jquery-3.2.0.min.js"></script>
</head>
<body class="beg-login-bg">
<div class="beg-login-box">
    <header>
        <h1>后台登录</h1>
    </header>
    <div class="beg-login-main">
        <form action="" class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe612;</i>
                </label>
                <input type="text" lay-verify="required" name="userName" lay-verify="userName" autocomplete="off"
                       placeholder="输入登录名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe642;</i>
                </label>
                <input type="password" lay-verify="required" name="userPwd" lay-verify="password" autocomplete="off"
                       placeholder="输入密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe642;</i>
                </label>
                <input type="text" lay-verify="required" style="width:142px;display: inline;" name="userVerify"
                       lay-verify="userVerify" autocomplete="off" placeholder="输入验证码" class="layui-input">
                <img title="点击换验证码"
                     onclick="this.src='../verify.php?'+Math.random();" src="../verify.php"
                     style="vertical-align: middle; border: 0px; height: 37px;cursor: pointer;"/>
            </div>

            <div class="layui-form-item">

                <div class="beg-pull-right">
                    <button class="layui-btn layui-btn-big" lay-submit lay-filter="login">
                        登录
                    </button>
                </div>

                <div class="beg-clear"></div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form();
        form.on('submit(login)', function (data) {
            $.ajax({
                url: 'user/user.php',
                type: "post",
                dataType: "json",
                data: 'method=adminLogin&usertel=' + $.trim(data.field.userName) + '&userpwd=' + $.trim(data.field.userPwd)
                + '&verifyCode=' + $.trim(data.field.userVerify),
                success: function (result) {
                    layer.msg(result.msg, {time: 800}, function () {
                        if (result.errorCode == 0) {
                            window.location.href = "index.php";
                        } else {
                            $('img').trigger('click');
                            if (result.errorCode == 1){
                                $('form.layui-form').find('input[name=userVerify]').val('');
                                $('form.layui-form').find('input[name=userVerify]').focus();
                            }else{
                                $('form.layui-form').find('input[name=userPwd]').val('');
                                $('form.layui-form').find('input[name=userPwd]').focus();
                            }
                        }
                    });
                }, error: function () {
                }
            });
            return false;
        });
    });
</script>
</body>
</html>